<?php


if( isset ($_POST['id']) )
{
	
	$id = $_POST['id'];
	
	switch($_POST['rang']) 
	{ 
	case "Utilisateur" : $rang = 1; break;
	case "Admin" : $rang = 2; break;
	case "resp" : $rang = 3; break;
	}

	$connect = connexion(SQLHOST,SQLUSER,SQLPASS,SQLDB);
	$req = 'UPDATE user SET rang = "'.$rang.'" WHERE id = ' . $id;
	$result = extraire($connect, $req);
	mysql_close($connect);

	redirect("index.php?module=administration",1);
echo "Traitement en cours";
}

if(isset($_SESSION['rang']) && $_SESSION['rang'] == 2)
{
	$connect = connexion( SQLHOST, SQLUSER, SQLPASS, SQLDB );
	$req = 'SELECT * FROM user';
	$result = extraire ( $connect, $req );
	$row = mysql_fetch_array ( $result );
	$num= @mysql_numrows($result);
	
?>	
	<table id="content">
		<thead>
			<tr bgcolor = "#A4A4A4">
				<td> <font face="Arial, Helvetica, sans-serif"><b>Id</b></font> </td>
				<td> <font face="Arial, Helvetica, sans-serif"><b>Nom</b></font> </td>
				<td> <font face="Arial, Helvetica, sans-serif"><b>E mail</b></font> </td>
				<td> <font face="Arial, Helvetica, sans-serif"><strong>Rang</strong></font> </td>
			</tr>
		</thead>
		<tbody>
		<?php
			$i=0;while ($i < $num)
			{
				$f1=mysql_result($result,$i,"id");
				$f2=mysql_result($result,$i,"nom");
				$f3=mysql_result($result,$i,"email");
				$f5=mysql_result($result,$i,"rang");

		?>
			<tr>
				<td> <font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font> </td>
				<td> <font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font> </td>
				<td> <font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font> </td>
				<td> <font face="Arial, Helvetica, sans-serif">
				
				<?php switch($f5) { case 1 : echo '			
			<form method="post" action="index.php?module=administration"><select name="rang">
			  <option value="Utilisateur" selected >Utilisateur</option>
			  <option value="Admin">Admin</option>
			  <option value="resp">Resp. de domaine</option>
			</select><INPUT type="hidden" value="'. $f1.'" name="id"><button class="button btn btn-warning btn-large" id="button" value="Modifier" type="submit" name="consultation">Modifier</button>
		</form>'; break; case 2 : echo '			<form method="post" action="index.php?module=administration"><select name="rang">
			  <option value="Utilisateur" >Utilisateur</option>
			  <option value="Admin" selected>Admin</option>
			  <option value="resp">Resp. de domaine</option>
			</select><INPUT type="hidden" value="'. $f1.'" name="id"><button class="button btn btn-warning btn-large" id="button" value="Modifier" type="submit" name="consultation">Modifier</button>
		</form>'; break; case 3 : echo '
						
						<form method="post" action="index.php?module=administration"><select name="rang">
			  <option value="Utilisateur"selected>Utilisateur</option>
			  <option value="Admin">Admin</option>
			  <option value="resp" selected>Resp. de domaine</option>
			</select><INPUT type="hidden" value="'. $f1.'" name="id"><button class="button btn btn-warning btn-large" id="button" value="Modifier" type="submit" name="consultation">Modifier</button>
		</form>'; break; } ?>
				
			
				
				
				</font> </td>
			</tr>
			
			


			

			

			
			
			
			<?php
			$i++; }
			?>		

		</tbody>
	</table>
	
<?php	
}
else
{
	echo '<p style="color:red">Vous n\'etes pas administrateur ! <a href="index.php">Revenir a l\'index</a></p>';
}

?>
